<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>列表渲染</title>
  </head>
  <body>
    <div id="app">
      <h1>水果列表：</h1>
      <input type="text" placeholder="请输入要添加水果的名字" id="input" />
      <button @click="fn1">点击添加输入框中的水果</button>
      <ul>
        <li v-for="item in list">{{item}}</li>
      </ul>
    </div>

    <script src="../lib/vue.global.js"></script>

    <script>
      const app = Vue.createApp({
        data() {
          return {
            list: ["Apple", "Orange", "西瓜"],
          };
        },
        methods: {
          fn1() {
            const inputDOM = document.querySelector("#input");
            const value = inputDOM.value.trim();
            if (!value) {
              alert("请输入水果名称");
            } else {
              this.list.push(value);
              inputDOM.value = "";
            }
          },
        },
      });
      app.mount("#app");
    </script>
  </body>
</html>
